qype.views.MapView = Class.create(View, {
			
	initialize: function($super, id) {
		// start with super initialize
		$super(id);
		
		// init attributes		
		this.latitude  = 0;
		this.longitude = 0;
		
		//Size of the map tile. Using square that can be cropped to fit to the view
		this.mapHeight = 640;
		this.mapWidth = 640;  
		
		this.mapImageUrl ="";
				
	    // create snippets here
		var mobileMap = new Snippet("mobileMap");		
		mobileMap.onDefault.template = '<div id="mapImageDiv" style="background-image:url(assets/ajax-loader.gif); background-position:center center;  background-repeat: no-repeat;  width: 100%; height: 100%;"></div><div class="ring_box"><div class="ring"></div></div>';
		
		this.registerSnippets({mobileMap:mobileMap});
	},
	
	/**
	 * Consturcts Map URL for tile based map services
	 * @param {Object} baseUrl Base URL of the map service in parametrized form
	 */
	constructMapUrl : function(baseUrl){
  
       baseUrl = baseUrl.replace(/%LAT%/g, this.latitude);
	   baseUrl = baseUrl.replace(/%LON%/g, this.longitude);
	   baseUrl = baseUrl.replace(/%WIDTH%/g, this.mapWidth);
	   baseUrl = baseUrl.replace(/%HEIGHT%/g, this.mapHeight);

	   this.mapImageUrl = baseUrl;	   
    },
	
	
	render: function($super, params) {
		$super(params);
		
		this.placeData = {
            place: params.placedata
        }
		
		if(params.placedata){
			if (params.placedata.point) {
				var arr = params.placedata.point.split(",")
				if(arr.length > 1){
					this.latitude  = arr[0];
					this.longitude = arr[1];
				}
			}
		}				
											
		//constuct URL				
		switch(qype.config.MAP_PROVIDER){
          case "g":
            	this.constructMapUrl(qype.config.G_MAP_BASE_URL);
            break;
          default:
            	this.constructMapUrl(qype.config.G_MAP_BASE_URL);
            break; 
        }		
				
		//preload map image
		var newMapImg = new Image();
		newMapImg.src = this.mapImageUrl;
	
		newMapImg.onload = function (evt) {
			var mapContainer = document.getElementById('mapImageDiv');			
       		mapContainer.style.backgroundImage = "url('"+newMapImg.src+"')";		
		};		
	}
});